//
//  XhwDynamicAnalyzeCtrl.m
//  SelfDriving
//
//  Created by 熊宏伟 on 2018/1/18.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "XhwDynamicAnalyzeCtrl.h"
#import "KPFenXiCell.h"
#import "BusinessService+WD.h"

@interface XhwDynamicAnalyzeCtrl ()
@property (weak, nonatomic) IBOutlet BaseTable *mainTable;

@end

@implementation XhwDynamicAnalyzeCtrl

{
    NSMutableArray *data;
    UILabel *notlabel;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"动态统计";
    data = [[NSMutableArray alloc]init];
    
    [self initData:1];
}

- (void)initData:(int)page {
    NSMutableDictionary *dic = [UserDefaults readUserDefaultObjectValueForKey:@"userLocation"];
    [dic setObject:[NSNumber numberWithInt:page] forKey:@"page"];
    
    [[BusinessService shareInstance] dynaimc_statistics:dic success:^(id result) {
        data = [_mainTable result:result olddata:data index:page];
        if (notlabel) {
            [notlabel removeFromSuperview];
        }
        notlabel = (UILabel *)[_mainTable notData];
        if (data.count == 0) {
            [self.view addSubview:notlabel];
            
        }
        else {
            [_mainTable reloadData];
        }
        
        _mainTable.header.hidden = YES;
    } failure:^(id result) {
        [SVProgressHUD showErrorWithStatus:result];
    }];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return data.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 15;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.000001f;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 300;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    KPFenXiCell *cell = [tableView dequeueReusableCellWithIdentifier:@"KPFenXiCell" forIndexPath:indexPath];
    NSLog(@"动态统计data数量->%lu",(unsigned long)data.count);
    NSLog(@"%ld",(long)indexPath.section);
    NSLog(@"%@",data[indexPath.section]);
    DTModel * xhwModel = data[indexPath.section];
    NSLog(@"%@",xhwModel.detail[@"title"]);
    cell.Dtmodel = xhwModel;
    
    return cell;
}
- (IBAction)backActino:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}



@end
